#!/bin/bash
#author 51yuki
#description: use yum install nginx server
#
BASEARCH=$(uname -i)
SYSTEM=$(cat /etc/centos-release|awk -F' ' '{if(NR==1) print $1}')
VERSION=$(cat /etc/centos-release|awk -F' ' '{if(NR==1) print $4}'|cut -d. -f1)


cd /etc/yum.repos.d && [ ! -f nginx.repo ] && \
cat > nginx.repo <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$VERSION/$BASEARCH/
gpgcheck=0
enabled=1
EOF
rpm -ql nginx && [ $? -eq 0 ] && echo "the server nginx is installing" && exit 2
yum -y install nginx 
cp /etc/nginx/nginx.conf{,.original}

vim /etc/nginx/nginx.conf <<VIM > /dev/null 2>&1
:%s/worker_processes  1;/worker_processes  2;/
:%s/worker_connections  1024;/worker_connections  4096;/
:%s/#gzip/server_tokens off;\r    gzip/
:wq
VIM
if [ "$VERSION" == "6" ];then
	chkconfig --add nginx
	chkconfig nginx on
	service nginx start
fi
if [ "$VERSION" == "7" ];then
	systemctl enable nginx
	systemctl start nginx
fi
